#include <iostream>
#include <unordered_map>
#include <cmath>
#include <vector>
#include <algorithm>

std::unordered_map<std::string, int> a = {
    {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
    {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
};

bool prime(int x) {
    if (x == 1) {
        return false;
    }
    for (int i = 2; i <= std::sqrt(x) + 1; i++) {
        if (x % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    std::string input;
    std::getline(std::cin, input);
    std::vector<std::string> b;
    std::string temp = "";
    for (char c : input) {
        if (c == ' ') {
            b.push_back(temp);
            temp = "";
        } else {
            temp += c;
        }
    }
    b.push_back(temp);

    if (b.size() != 3) {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }

    std::vector<int> otv;
    int minn = 809;
    std::vector<int> razn;
    std::string c = "";
    for (const std::string& i : b) {
        c += std::to_string(a[i]);
    }
    int num = std::stoi(c);

    for (int i = 100; i < 999; i++) {
        if (prime(i)) {
            if (std::abs(num - i) < minn) {
                minn = std::abs(num - i);
                otv.push_back(i);
                razn.push_back(std::abs(num - i));
            }
        }
    }

    int s = *std::min_element(razn.begin(), razn.end());
    std::vector<int> ss;
    for (int i = 0; i < otv.size(); i++) {
        if (razn[i] == s) {
            ss.push_back(otv[i]);
        }
    }
    std::cout << *std::min_element(ss.begin(), ss.end()) << std::endl;

    return 0;
}

